'* Copyright (c) 2017, Oracle And/Or its affiliates. All rights reserved. */

'******************************************************************************
' *
' * You may Not use the identified files except in compliance with The MIT
' * License (the "License.")
' *
' * You may obtain a copy of the License at
' * https://github.com/oracle/Oracle.NET/blob/master/LICENSE
' *
' * Unless required by applicable law Or agreed to in writing, software
' * distributed under the License Is distributed on an "AS IS" BASIS, WITHOUT
' * WARRANTIES Or CONDITIONS OF ANY KIND, either express Or implied.
' *
' * See the License for the specific language governing permissions And
' * limitations under the License.
' *
' *****************************************************************************/

'**************************************************************************
'@author  Abhijeet Kulkarni
'@version 1.0
'Development Environment        :  MS Visual Studio .Net
'Name of the File               :  RowUpdate.vb
'Creation/Modification History  :
'                                  17-Mar-2003     Created

'Overview: This file contains the definition of class RowUpdate. This class has
'GUI components required by this application. It also has supporting methods
'that handle events generated by widgets placed on the main form. 
'**************************************************************************

Imports System.Threading
Public Class RowUpdate
    Inherits System.Windows.Forms.Form
    Protected dba As DBAccess
    Protected statusbool As Boolean

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call
        'Create instance of the database access helper class and pass the reference
        'of status window to this object
        dba = New DBAccess(StatusBox)
    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
    Friend WithEvents Connection As System.Windows.Forms.GroupBox
    Friend WithEvents UserNameLabel As System.Windows.Forms.Label
    Friend WithEvents UserName As System.Windows.Forms.TextBox
    Friend WithEvents PasswordLabel As System.Windows.Forms.Label
    Friend WithEvents Password As System.Windows.Forms.TextBox
    Friend WithEvents ConnectStringLabel As System.Windows.Forms.Label
    Friend WithEvents ButtonConnect As System.Windows.Forms.Button
    Friend WithEvents ButtonExit As System.Windows.Forms.Button
    Friend WithEvents StatusLabel As System.Windows.Forms.Label
    Friend WithEvents Status As System.Windows.Forms.Label
    Friend WithEvents StatusBox As System.Windows.Forms.TextBox
    Friend WithEvents DataSource As System.Windows.Forms.TextBox
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents ButtonUpdate As System.Windows.Forms.Button
    Friend WithEvents GroupBoxupdating1 As System.Windows.Forms.GroupBox
    Friend WithEvents GroupBox2 As System.Windows.Forms.GroupBox
    Friend WithEvents UpdatingEnabled As System.Windows.Forms.RadioButton
    Friend WithEvents UpdatingDisabled As System.Windows.Forms.RadioButton
    Friend WithEvents UpdatedEnabled As System.Windows.Forms.RadioButton
    Friend WithEvents UpdatedDisabled As System.Windows.Forms.RadioButton
    Friend WithEvents ButtonApply As System.Windows.Forms.Button
    Friend WithEvents CountryGrid As System.Windows.Forms.DataGrid
    Friend WithEvents DataGridTableStyle1 As System.Windows.Forms.DataGridTableStyle
    Friend WithEvents TextBoxCountryname As System.Windows.Forms.DataGridTextBoxColumn
    Friend WithEvents TextBoxpopulation As System.Windows.Forms.DataGridTextBoxColumn
    Friend WithEvents TextBoxLanguage As System.Windows.Forms.DataGridTextBoxColumn
    Friend WithEvents TextBoxCurrency As System.Windows.Forms.DataGridTextBoxColumn
    Friend WithEvents ButtonDisconnect As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.Label1 = New System.Windows.Forms.Label
        Me.GroupBox1 = New System.Windows.Forms.GroupBox
        Me.StatusBox = New System.Windows.Forms.TextBox
        Me.UserNameLabel = New System.Windows.Forms.Label
        Me.UserName = New System.Windows.Forms.TextBox
        Me.PasswordLabel = New System.Windows.Forms.Label
        Me.Password = New System.Windows.Forms.TextBox
        Me.Connection = New System.Windows.Forms.GroupBox
        Me.ButtonDisconnect = New System.Windows.Forms.Button
        Me.Status = New System.Windows.Forms.Label
        Me.StatusLabel = New System.Windows.Forms.Label
        Me.ButtonExit = New System.Windows.Forms.Button
        Me.ButtonConnect = New System.Windows.Forms.Button
        Me.DataSource = New System.Windows.Forms.TextBox
        Me.ConnectStringLabel = New System.Windows.Forms.Label
        Me.Label2 = New System.Windows.Forms.Label
        Me.ButtonUpdate = New System.Windows.Forms.Button
        Me.GroupBoxupdating1 = New System.Windows.Forms.GroupBox
        Me.UpdatingDisabled = New System.Windows.Forms.RadioButton
        Me.UpdatingEnabled = New System.Windows.Forms.RadioButton
        Me.GroupBox2 = New System.Windows.Forms.GroupBox
        Me.UpdatedDisabled = New System.Windows.Forms.RadioButton
        Me.UpdatedEnabled = New System.Windows.Forms.RadioButton
        Me.ButtonApply = New System.Windows.Forms.Button
        Me.CountryGrid = New System.Windows.Forms.DataGrid
        Me.DataGridTableStyle1 = New System.Windows.Forms.DataGridTableStyle
        Me.TextBoxCountryname = New System.Windows.Forms.DataGridTextBoxColumn
        Me.TextBoxpopulation = New System.Windows.Forms.DataGridTextBoxColumn
        Me.TextBoxLanguage = New System.Windows.Forms.DataGridTextBoxColumn
        Me.TextBoxCurrency = New System.Windows.Forms.DataGridTextBoxColumn
        Me.GroupBox1.SuspendLayout()
        Me.Connection.SuspendLayout()
        Me.GroupBoxupdating1.SuspendLayout()
        Me.GroupBox2.SuspendLayout()
        CType(Me.CountryGrid, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'Label1
        '
        Me.Label1.Font = New System.Drawing.Font("Arial", 16.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label1.Location = New System.Drawing.Point(24, 8)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(496, 24)
        Me.Label1.TabIndex = 0
        Me.Label1.Text = "Row Update Event Handler Application"
        Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'GroupBox1
        '
        Me.GroupBox1.Controls.Add(Me.StatusBox)
        Me.GroupBox1.Location = New System.Drawing.Point(8, 336)
        Me.GroupBox1.Name = "GroupBox1"
        Me.GroupBox1.Size = New System.Drawing.Size(544, 184)
        Me.GroupBox1.TabIndex = 1
        Me.GroupBox1.TabStop = False
        Me.GroupBox1.Text = "Status Window"
        '
        'StatusBox
        '
        Me.StatusBox.Font = New System.Drawing.Font("Verdana", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.StatusBox.Location = New System.Drawing.Point(8, 16)
        Me.StatusBox.Multiline = True
        Me.StatusBox.Name = "StatusBox"
        Me.StatusBox.ReadOnly = True
        Me.StatusBox.ScrollBars = System.Windows.Forms.ScrollBars.Vertical
        Me.StatusBox.Size = New System.Drawing.Size(528, 160)
        Me.StatusBox.TabIndex = 35
        '
        'UserNameLabel
        '
        Me.UserNameLabel.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.25!)
        Me.UserNameLabel.Location = New System.Drawing.Point(16, 56)
        Me.UserNameLabel.Name = "UserNameLabel"
        Me.UserNameLabel.Size = New System.Drawing.Size(80, 16)
        Me.UserNameLabel.TabIndex = 0
        Me.UserNameLabel.Text = "User Name"
        '
        'UserName
        '
        Me.UserName.Location = New System.Drawing.Point(96, 56)
        Me.UserName.Name = "UserName"
        Me.UserName.Size = New System.Drawing.Size(88, 20)
        Me.UserName.TabIndex = 0
        Me.UserName.Text = "scott"
        '
        'PasswordLabel
        '
        Me.PasswordLabel.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.25!)
        Me.PasswordLabel.Location = New System.Drawing.Point(192, 56)
        Me.PasswordLabel.Name = "PasswordLabel"
        Me.PasswordLabel.Size = New System.Drawing.Size(72, 24)
        Me.PasswordLabel.TabIndex = 0
        Me.PasswordLabel.Text = "Password"
        '
        'Password
        '
        Me.Password.Location = New System.Drawing.Point(264, 56)
        Me.Password.Name = "Password"
        Me.Password.Size = New System.Drawing.Size(80, 20)
        Me.Password.TabIndex = 1
        Me.Password.Text = "<PASSWORD>"
        '
        'Connection
        '
        Me.Connection.Controls.Add(Me.ButtonDisconnect)
        Me.Connection.Controls.Add(Me.Status)
        Me.Connection.Controls.Add(Me.StatusLabel)
        Me.Connection.Controls.Add(Me.ButtonExit)
        Me.Connection.Controls.Add(Me.ButtonConnect)
        Me.Connection.Controls.Add(Me.DataSource)
        Me.Connection.Controls.Add(Me.ConnectStringLabel)
        Me.Connection.Location = New System.Drawing.Point(8, 40)
        Me.Connection.Name = "Connection"
        Me.Connection.Size = New System.Drawing.Size(544, 80)
        Me.Connection.TabIndex = 0
        Me.Connection.TabStop = False
        Me.Connection.Text = "Connection Details"
        '
        'ButtonDisconnect
        '
        Me.ButtonDisconnect.Enabled = False
        Me.ButtonDisconnect.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.ButtonDisconnect.Location = New System.Drawing.Point(336, 48)
        Me.ButtonDisconnect.Name = "ButtonDisconnect"
        Me.ButtonDisconnect.Size = New System.Drawing.Size(88, 24)
        Me.ButtonDisconnect.TabIndex = 2
        Me.ButtonDisconnect.Text = "Disconnect "
        '
        'Status
        '
        Me.Status.Font = New System.Drawing.Font("Arial", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Status.ForeColor = System.Drawing.Color.Red
        Me.Status.ImageAlign = System.Drawing.ContentAlignment.BottomCenter
        Me.Status.Location = New System.Drawing.Point(80, 56)
        Me.Status.Name = "Status"
        Me.Status.Size = New System.Drawing.Size(120, 16)
        Me.Status.TabIndex = 0
        Me.Status.Text = "Not Connected"
        '
        'StatusLabel
        '
        Me.StatusLabel.Font = New System.Drawing.Font("Arial", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.StatusLabel.Location = New System.Drawing.Point(16, 56)
        Me.StatusLabel.Name = "StatusLabel"
        Me.StatusLabel.Size = New System.Drawing.Size(48, 16)
        Me.StatusLabel.TabIndex = 0
        Me.StatusLabel.Text = "Status: "
        '
        'ButtonExit
        '
        Me.ButtonExit.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.ButtonExit.Location = New System.Drawing.Point(448, 48)
        Me.ButtonExit.Name = "ButtonExit"
        Me.ButtonExit.Size = New System.Drawing.Size(88, 24)
        Me.ButtonExit.TabIndex = 2
        Me.ButtonExit.Text = "Exit"
        '
        'ButtonConnect
        '
        Me.ButtonConnect.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.ButtonConnect.Location = New System.Drawing.Point(224, 48)
        Me.ButtonConnect.Name = "ButtonConnect"
        Me.ButtonConnect.Size = New System.Drawing.Size(88, 24)
        Me.ButtonConnect.TabIndex = 1
        Me.ButtonConnect.Text = "Connect "
        '
        'DataSource
        '
        Me.DataSource.Location = New System.Drawing.Point(448, 16)
        Me.DataSource.Name = "DataSource"
        Me.DataSource.Size = New System.Drawing.Size(88, 20)
        Me.DataSource.TabIndex = 0
        Me.DataSource.Text = "oracle"
        '
        'ConnectStringLabel
        '
        Me.ConnectStringLabel.Font = New System.Drawing.Font("Arial", 10.25!)
        Me.ConnectStringLabel.Location = New System.Drawing.Point(344, 16)
        Me.ConnectStringLabel.Name = "ConnectStringLabel"
        Me.ConnectStringLabel.Size = New System.Drawing.Size(104, 24)
        Me.ConnectStringLabel.TabIndex = 4
        Me.ConnectStringLabel.Text = "Data Source"
        '
        'Label2
        '
        Me.Label2.Font = New System.Drawing.Font("Arial", 10.25!, System.Drawing.FontStyle.Bold)
        Me.Label2.Location = New System.Drawing.Point(216, 8)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(96, 24)
        Me.Label2.TabIndex = 0
        Me.Label2.Text = "Source Code "
        '
        'ButtonUpdate
        '
        Me.ButtonUpdate.Enabled = False
        Me.ButtonUpdate.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold)
        Me.ButtonUpdate.Location = New System.Drawing.Point(456, 248)
        Me.ButtonUpdate.Name = "ButtonUpdate"
        Me.ButtonUpdate.Size = New System.Drawing.Size(88, 24)
        Me.ButtonUpdate.TabIndex = 2
        Me.ButtonUpdate.Text = "Update"
        '
        'GroupBoxupdating1
        '
        Me.GroupBoxupdating1.Controls.Add(Me.UpdatingDisabled)
        Me.GroupBoxupdating1.Controls.Add(Me.UpdatingEnabled)
        Me.GroupBoxupdating1.Location = New System.Drawing.Point(8, 280)
        Me.GroupBoxupdating1.Name = "GroupBoxupdating1"
        Me.GroupBoxupdating1.Size = New System.Drawing.Size(208, 48)
        Me.GroupBoxupdating1.TabIndex = 10
        Me.GroupBoxupdating1.TabStop = False
        Me.GroupBoxupdating1.Text = "OracleRowUpdatingEventHandler"
        '
        'UpdatingDisabled
        '
        Me.UpdatingDisabled.Enabled = False
        Me.UpdatingDisabled.Location = New System.Drawing.Point(112, 24)
        Me.UpdatingDisabled.Name = "UpdatingDisabled"
        Me.UpdatingDisabled.Size = New System.Drawing.Size(72, 16)
        Me.UpdatingDisabled.TabIndex = 1
        Me.UpdatingDisabled.Text = "Disabled"
        '
        'UpdatingEnabled
        '
        Me.UpdatingEnabled.Checked = True
        Me.UpdatingEnabled.Enabled = False
        Me.UpdatingEnabled.Location = New System.Drawing.Point(24, 24)
        Me.UpdatingEnabled.Name = "UpdatingEnabled"
        Me.UpdatingEnabled.Size = New System.Drawing.Size(112, 16)
        Me.UpdatingEnabled.TabIndex = 0
        Me.UpdatingEnabled.TabStop = True
        Me.UpdatingEnabled.Text = "Enabled"
        '
        'GroupBox2
        '
        Me.GroupBox2.Controls.Add(Me.UpdatedDisabled)
        Me.GroupBox2.Controls.Add(Me.UpdatedEnabled)
        Me.GroupBox2.Location = New System.Drawing.Point(240, 280)
        Me.GroupBox2.Name = "GroupBox2"
        Me.GroupBox2.Size = New System.Drawing.Size(208, 48)
        Me.GroupBox2.TabIndex = 11
        Me.GroupBox2.TabStop = False
        Me.GroupBox2.Text = "OracleRowUpdatedEventHandler"
        '
        'UpdatedDisabled
        '
        Me.UpdatedDisabled.Enabled = False
        Me.UpdatedDisabled.Location = New System.Drawing.Point(96, 24)
        Me.UpdatedDisabled.Name = "UpdatedDisabled"
        Me.UpdatedDisabled.Size = New System.Drawing.Size(72, 16)
        Me.UpdatedDisabled.TabIndex = 1
        Me.UpdatedDisabled.Text = "Disabled"
        '
        'UpdatedEnabled
        '
        Me.UpdatedEnabled.Checked = True
        Me.UpdatedEnabled.Enabled = False
        Me.UpdatedEnabled.Location = New System.Drawing.Point(16, 24)
        Me.UpdatedEnabled.Name = "UpdatedEnabled"
        Me.UpdatedEnabled.Size = New System.Drawing.Size(104, 16)
        Me.UpdatedEnabled.TabIndex = 0
        Me.UpdatedEnabled.TabStop = True
        Me.UpdatedEnabled.Text = "Enabled"
        '
        'ButtonApply
        '
        Me.ButtonApply.Enabled = False
        Me.ButtonApply.Location = New System.Drawing.Point(456, 304)
        Me.ButtonApply.Name = "ButtonApply"
        Me.ButtonApply.Size = New System.Drawing.Size(88, 24)
        Me.ButtonApply.TabIndex = 3
        Me.ButtonApply.Text = "Apply"
        '
        'CountryGrid
        '
        Me.CountryGrid.CaptionText = "Country Table"
        Me.CountryGrid.DataMember = ""
        Me.CountryGrid.HeaderForeColor = System.Drawing.SystemColors.ControlText
        Me.CountryGrid.Location = New System.Drawing.Point(8, 136)
        Me.CountryGrid.Name = "CountryGrid"
        Me.CountryGrid.PreferredColumnWidth = 100
        Me.CountryGrid.Size = New System.Drawing.Size(440, 136)
        Me.CountryGrid.TabIndex = 4
        Me.CountryGrid.TableStyles.AddRange(New System.Windows.Forms.DataGridTableStyle() {Me.DataGridTableStyle1})
        '
        'DataGridTableStyle1
        '
        Me.DataGridTableStyle1.DataGrid = Me.CountryGrid
        Me.DataGridTableStyle1.GridColumnStyles.AddRange(New System.Windows.Forms.DataGridColumnStyle() {Me.TextBoxCountryname, Me.TextBoxpopulation, Me.TextBoxLanguage, Me.TextBoxCurrency})
        Me.DataGridTableStyle1.HeaderForeColor = System.Drawing.SystemColors.ControlText
        '
        'TextBoxCountryname
        '
        Me.TextBoxCountryname.Format = ""
        Me.TextBoxCountryname.FormatInfo = Nothing
        Me.TextBoxCountryname.MappingName = "COUNTRYNAME"
        Me.TextBoxCountryname.ReadOnly = True
        Me.TextBoxCountryname.Width = 20
        '
        'TextBoxpopulation
        '
        Me.TextBoxpopulation.Format = ""
        Me.TextBoxpopulation.FormatInfo = Nothing
        Me.TextBoxpopulation.MappingName = "POPULATION"
        Me.TextBoxpopulation.ReadOnly = True
        Me.TextBoxpopulation.Width = 20
        '
        'TextBoxLanguage
        '
        Me.TextBoxLanguage.Format = ""
        Me.TextBoxLanguage.FormatInfo = Nothing
        Me.TextBoxLanguage.MappingName = "LANGUAGE"
        Me.TextBoxLanguage.NullText = "NULL"
        Me.TextBoxLanguage.Width = 20
        '
        'TextBoxCurrency
        '
        Me.TextBoxCurrency.Format = ""
        Me.TextBoxCurrency.FormatInfo = Nothing
        Me.TextBoxCurrency.MappingName = "CURRENCY"
        Me.TextBoxCurrency.NullText = "NULL"
        Me.TextBoxCurrency.Width = 20
        '
        'RowUpdate
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(552, 514)
        Me.Controls.Add(Me.CountryGrid)
        Me.Controls.Add(Me.ButtonApply)
        Me.Controls.Add(Me.GroupBox2)
        Me.Controls.Add(Me.GroupBoxupdating1)
        Me.Controls.Add(Me.ButtonUpdate)
        Me.Controls.Add(Me.Password)
        Me.Controls.Add(Me.PasswordLabel)
        Me.Controls.Add(Me.UserName)
        Me.Controls.Add(Me.UserNameLabel)
        Me.Controls.Add(Me.GroupBox1)
        Me.Controls.Add(Me.Label1)
        Me.Controls.Add(Me.Connection)
        Me.Controls.Add(Me.Label2)
        Me.MaximizeBox = False
        Me.MaximumSize = New System.Drawing.Size(568, 552)
        Me.MinimumSize = New System.Drawing.Size(568, 552)
        Me.Name = "RowUpdate"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "Row Update Event Handler Application"
        Me.GroupBox1.ResumeLayout(False)
        Me.GroupBox1.PerformLayout()
        Me.Connection.ResumeLayout(False)
        Me.Connection.PerformLayout()
        Me.GroupBoxupdating1.ResumeLayout(False)
        Me.GroupBox2.ResumeLayout(False)
        CType(Me.CountryGrid, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub

#End Region

    '**************************************************************************
    'This method handles the Connect button click event. With the help of DBAccess
    'class it tries to connect to the database. If connection is obtained then 
    'other GUI components are enabled.
    '**************************************************************************
    Private Sub ButtonConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonConnect.Click
        
        ButtonExit.Enabled = False
        Dim tempStr As String = UserName.Text
        Dim flag As Boolean = True
        'Check if Username width is more than 0 characters
        If (tempStr.Length = 0) Then
            flag = False
            MessageBox.Show("Username cannot be a null String", "Error Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Return
        End If
        tempStr = Password.Text
        'Check if Password width is more than 0 characters
        If (tempStr.Length = 0) Then
            flag = False
            MessageBox.Show("Password cannot be a null String", "Error Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Return
        End If
        tempStr = DataSource.Text
        'Check if dataSource width is more than 0 characters
        If (tempStr.Length = 0) Then
            flag = False
            MessageBox.Show("DataSource cannot be a null String", "Error Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Return
        End If

        If (flag = True) Then
            'Trying to connect disable connect button
            ButtonConnect.Enabled = False
            'Try to connect to the database 
            dba.connect(UserName.Text, Password.Text, DataSource.Text)
            'If no exception is thrown set status to true
            statusbool = True
        End If

        'Check if the program is connected to the database and enable user 
        'controls if it is connected.
        flag = dba.isConnected
        If (flag = True) Then
            Status.Text = "Connected"
            Status.ForeColor = Color.Green
            Status.Update()
            dba.CreateTable()
            dba.PopulateDataGrid(CountryGrid)
            ButtonUpdate.Enabled = True
            UpdatingEnabled.Enabled = True
            UpdatingDisabled.Enabled = True
            UpdatedEnabled.Enabled = True
            UpdatedDisabled.Enabled = True
            ButtonApply.Enabled = True
            ButtonConnect.Enabled = False
            ButtonDisconnect.Enabled = True
            ButtonExit.Enabled = False
            CountryGrid.Enabled = True
            ButtonUpdate.Enabled = True
            ButtonApply.Enabled = True
            ButtonExit.Enabled = False
        Else
            'Not connected to database enable connect button
            Status.Text = "Not Connected"
            Status.ForeColor = Color.Red
            ButtonConnect.Enabled = True
            ButtonDisconnect.Enabled = False
            ButtonUpdate.Enabled = False
            ButtonApply.Enabled = False
            ButtonExit.Enabled = True
        End If

    End Sub

    '**************************************************************************
    'This method handles the Exit button click event. Closes the connection and
    'exits the application.
    '**************************************************************************
    Private Sub ButtonExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonExit.Click
        'Update status text and color 
        Status.Text = "Exiting, Please wait"
        Status.ForeColor = Color.Red
        Status.Update()
        Thread.CurrentThread.Sleep(1500)
        'Exit the application
        Application.Exit()
    End Sub

    '**************************************************************************
    'This method handles the Update button click event. Updates the database with
    'the modified DataGrid entries.
    '**************************************************************************
    Private Sub ButtonUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonUpdate.Click
        'Update the database
        dba.UpdateRecords()
    End Sub

    '**************************************************************************
    'This method handles the Apply button click event. Either registers or 
    'de-registers the event handlers depending on radio button states.
    '**************************************************************************
    Private Sub ButtonApply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonApply.Click

        'Check the radio buttons that are selected and call appropriate methods.   
        If (UpdatingEnabled.Checked = True) Then
            dba.AddUpdatingHandler()
        End If

        If (UpdatingDisabled.Checked = True) Then
            dba.RemoveUpdatingHandler()
        End If

        If (UpdatedEnabled.Checked = True) Then
            dba.AddUpdatedHandler()
        End If

        If (UpdatedDisabled.Checked = True) Then
            dba.RemoveUpdatedHandler()
        End If
        StatusBox.AppendText("Event Handlers Updated" + Environment.NewLine)
        StatusBox.Update()
    End Sub

    '**************************************************************************
    'This method prevents insertion of new row
    '**************************************************************************
    Private Sub CountryGrid_CurrentCellChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CountryGrid.CurrentCellChanged
        If (CountryGrid.CurrentCell.RowNumber > 3) Then
            CountryGrid.CurrentCell = New DataGridCell(3, CountryGrid.CurrentCell.ColumnNumber)
        End If
    End Sub

    '**************************************************************************
    'This method is called when users press Disconnect button
    '**************************************************************************
    Private Sub ButtonDisconnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonDisconnect.Click
        ButtonDisconnect.Enabled = False
        CountryGrid.Enabled = False
        dba.RemoveUpdatedHandler()
        dba.RemoveUpdatingHandler()
        ButtonUpdate.Enabled = False
        ButtonApply.Enabled = False
        dba.closeConnection()
        Status.Text = "Not Connected"
        Status.ForeColor = Color.Red
        ButtonExit.Enabled = True
        ButtonConnect.Enabled = True
        ButtonExit.Enabled = True
    End Sub

    '**************************************************************************
    'This method is called when user closes the form
    '**************************************************************************
    Private Sub Form_Close(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Closed
        ButtonUpdate.Enabled = False
        ButtonApply.Enabled = False
        ButtonExit.Enabled = False
        ButtonConnect.Enabled = False
        ButtonDisconnect.Enabled = False
        dba.closeConnection()
        Application.Exit()
    End Sub


End Class
